﻿using GalaSoft.MvvmLight;
using SurveyControl.Controls;
using System.Collections.ObjectModel;

namespace DemoSurveyControl
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {

        /// <summary>
        /// The <see cref="ListItem" /> property's name.
        /// </summary>
        public const string ListItemPropertyName = "ListItem";

        private ObservableCollection<QuestionControl> _ListItem = null;

        /// <summary>
        /// Gets the ListItem property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public ObservableCollection<QuestionControl> ListItem
        {
            get
            {
                return _ListItem;
            }

            set
            {
                if (_ListItem == value)
                {
                    return;
                }

                _ListItem = value;
                RaisePropertyChanged(ListItemPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="SelectedItem" /> property's name.
        /// </summary>
        public const string SelectedItemPropertyName = "SelectedItem";

        private QuestionControl _SelectedControl = null;

        /// <summary>
        /// Gets the SelectedItem property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public QuestionControl SelectedItem
        {
            get
            {
                return _SelectedControl;
            }

            set
            {
                if (_SelectedControl == value)
                {
                    return;
                }

                _SelectedControl = value;
                RaisePropertyChanged(SelectedItemPropertyName);
            }
        }

        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            ListItem = new ObservableCollection<QuestionControl>()
            {
                new QuestionControl() { Question = "Question 1 ?", ItemsSource = new ObservableCollection<Answer>() { new Answer("Reponse 1"), new Answer("Reponse 2"), new Answer("Reponse 3") }, },
                new QuestionControl() { Question = "Question 2 ?", ItemsSource = new ObservableCollection<Answer>() { new Answer("Une voiture"), new Answer("Un train"), new Answer("Un avion") }, },
                new QuestionControl() { Question = "Question 3 ?", ItemsSource = new ObservableCollection<Answer>() { new Answer("A point"), new Answer("Bien cuit"), new Answer("Saignant") }, },
            };

            SelectedItem = ListItem[1];
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}
        }

        ////public override void Cleanup()
        ////{
        ////    // Clean own resources if needed

        ////    base.Cleanup();
        ////}
    }
}